<!-- UserModel.php-->
<?php 
	require '../common/ConnDB.php'; 
	require '../common/config.php';
	require 'Model.php';
	class DeModel extends Model{
		function __Construct(){
			parent::__Construct();
		}
		function getDeList(){
			$sql = 'select * from des';
			$data = $this->conn->query($sql);
			//$this->conn = new ConnDB();
			return $data;
		}

		function getdeinfor($dename){
			$sql = "select * from des where dename like '%".$dename."%' limit 0,5 ";;
			$data = $this->conn->query($sql);
			return $data;
		}

		function getUserByID($id){
			$sql = "select * from des where deid=".$id;
			$data = $this->conn->query($sql);
			return $data;
		}

		function Updatedepartment($data){
			if(!empty($_FILES["dephoto"]["name"])){
  				$dephoto = parent::uploadfile('dephoto','../images/',array('png','jpg','gif'));
  			}
		    else{
		  		$dephoto='';
		  	}
		  	$depart = array(
				'deid' =>$_POST['id'],
				'dename' => $_POST['dename'],
				'duty' => $_POST['duty'],
				'activityid' => $_POST['activityid'],
				'dephoto' => $dephoto,
				'minister' => $_POST['minister'],
				'member' => $_POST['member'],
				);
			$sql="update des set deid='$depart[deid]',dename='$depart[dename]',duty='$depart[duty]',activityid='$depart[activityid]',dephoto='$depart[dephoto]',minister='$depart[minister]',member='$depart[member]' where deid=".$depart['deid'];
			//echo "$sql";
			$result = $this->conn->query($sql);
			return $result;
		}

		function addde($data){
			//如果选择了照片，则上传照片文件
			if(!empty($_FILES["dephoto"]["name"])){
  				$dephoto = parent::uploadfile('dephoto','../images/',array('png','jpg','gif'));
  			}
		    else{
		  		$dephoto='';
		  	}
			$user = array(
				'deid' =>'',
				'dename' => $data['dename'],
				'duty' => $data['duty'],
				'activityid' => $data['activityid'],
				'dephoto' => $dephoto,
				'minister' => $data['minister'],
				'member' => $data['member'],
				);
			$keys = implode(',',array_keys($user));
			$values = implode("','",array_values($user));
			/*$sql = "insert into users values ('$user[uid]','$user[uname]','$user[password]','$user[gender]','$user[birthdate]','$user[hobby]','$user[degree]','$user[intro]','$user[pic]')";*/
			$sql="insert into des ({$keys}) VALUES ('{$values}')";
			//echo "$sql";
			$result = $this->conn->query($sql);
			return $result;
		}

		function Deldepartment($id){
			$sql = "Delete from des where deid=".$id;
			$data = $this->conn->query($sql);
			return $data;
		}
	}
 ?>